package com.sptpc.demo.controller;

import com.sptpc.demo.controller.requests.AddOrderRequest;
import com.sptpc.demo.model.Order;
import com.sptpc.demo.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;
    @PostMapping("/")
    public Order addNewOrder(@RequestBody AddOrderRequest request){
        log.info("订单信息：{}",request);
        Order order=new Order();
        BeanUtils.copyProperties(request,order);
        orderService.addOrder(order,request.getItems());
        return order;
    }
    //get
    @GetMapping("/{customer}")
    public List<Order> getOrderByCustomer(@PathVariable String customer){
        return orderService.getOrderByCustomer(customer);

    }
}
